package com.sgb.kjwl.view.widget.manage


import android.content.Context
import android.text.TextUtils
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.sgb.kjwl.R
import com.swgk.core.util.PickSelectEntity
import com.sgb.link.view.adapter.PickAdapter
import com.swgk.core.dialog.BasePopWindow
import com.swgk.core.dialog.PopViewHolder
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick

class InquiryTypePopWindow(context: Context?) : BasePopWindow<Any>(context){
    private lateinit var mRecyclerView: RecyclerView
    private lateinit var mAdapter : PickAdapter

    override fun popLayout(): Int {
        return R.layout.layout_popwindow_inquiry_type
    }

    override fun initView(holder: PopViewHolder?) {
        mRecyclerView = holder!!.pop!!.findViewById(R.id.recycle_view)
        mRecyclerView.layoutManager = GridLayoutManager(mContext, 4)
        mAdapter = PickAdapter(mContext, null, R.layout.popwindow_white_item)
        mAdapter.setItemSelect(true)
        mAdapter.setOnItemClick(object : AdapterOnItemClick<PickSelectEntity<*>>(){
            override fun onItemClick(t: PickSelectEntity<*>?, position: Int) {
                if (onResultClick != null) {
                    onResultClick.result(t!!.no, t.projectscale, position)
                }
                mAdapter.setDefItem(position)
                dissMiss()
            }
        })
        mRecyclerView.adapter = mAdapter
    }

    fun setDatas(datas : ArrayList<PickSelectEntity<*>>){
        this.setDatas(datas, PickSelectEntity<Any>())
    }


    fun setDatas(datas : ArrayList<PickSelectEntity<*>>, hisEntity: PickSelectEntity<*>){//回显
        mAdapter.datas = datas
        mAdapter.setDefItem(-1)
        for (entity in mAdapter.datas){
            if (TextUtils.equals(entity.projectscale, hisEntity.projectscale)){
                val position = mAdapter.datas.indexOf(entity)
                mAdapter.setDefItem(position)
                break
            }
        }

    }

}